package com.jc.service.vrt;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSONObject;
import com.jc.common.util.Base64Util;
import com.jc.common.util.DateTimeUtil;
import com.jc.common.util.HttpUtil;
import com.jc.common.util.MD5;
import com.jc.service.api.appgame.model.RechargeParam;

public class Vrt {

	public static void main(String[] args) {
		
		try {
			
//			login();
			//sing();
			//staticRequest();
			
			recharge();
			query();
			
//			test();
			
		}catch (Exception e) {
			e.printStackTrace();
		}
		
		
		

	}
	
	public static void test() {
		
		String ss = Base64Util.decode("eyJhbW91bnQiOjIwMDAsIm9yZGVySWQiOiIyMDE5MDQyNTExMzExNjA0MzY4OTYiLCJzdGF0ZSI6MSwidXNlcklkIjo2Mjk1Mjh9");
		System.out.println(ss);
		
	}
	
	public static void query() throws Exception {
		
		
		String url = "http://localhost:8080/game/api"; //本机
		url = "http://47.101.163.99:8081/game-web/api"; //测试
		url = "http://my.vrtclub.io/game/api";//生产
		//url = "http://47.102.39.117:8080/game/api";
		String mothed = "api.appgame.query";
		String appKey="4g4gs65gfgsf4gf";
		String appsecret = "as323434ds454gfdd";
		String reqSource="SHENYANG_APP_GAME";
		String timestamp="" + new Date().getTime();
				
		//组织签名数据
		String str = appKey + appsecret + timestamp;
		str = Base64Util.encode(str);
		String sign = MD5.passmd5(str);
		//组织签名数据结束
		
		Map<String ,Object> paramMap = new HashMap<String ,Object>();
		paramMap.put("appKey", appKey);
		paramMap.put("reqSource", reqSource);
		paramMap.put("method", mothed);
		paramMap.put("sign", sign);
		paramMap.put("timestamp", timestamp);
		
		//userId
		Map<String ,Object> loginMap = new HashMap<String ,Object>();
		loginMap.put("userId", "609769");
		
		String ds = Base64Util.encode(JSONObject.toJSONString(loginMap));
		
		
		
		Map<String ,Object> ppmap = new HashMap<String ,Object>();
		ppmap.put("encrypt", ds);
		
		paramMap.put("data", ppmap);
		
		String body = JSONObject.toJSONString(paramMap);
		System.out.println(body);
		String ret = HttpUtil.postJson(url, body, null);
		System.out.println(ret);
	}
	
	//secret = "as323434ds454gfdd";
	
	public static void login() throws Exception {
		String url = "http://localhost:8080/game/api";//生产
		url = "http://47.101.163.99:8081/game-web/api";//测试
		url = "http://my.vrtclub.io/game/api";//生产
		String mothed = "api.appgame.login";
		String appKey="4g4gs65gfgsf4gf";
		String appsecret = "as323434ds454gfdd";
		String reqSource="SHENYANG_APP_GAME";
		String timestamp="" + new Date().getTime();
		
		
		//组织签名数据
		String str = appKey + appsecret + timestamp;
		str = Base64Util.encode(str);
		String sign = MD5.passmd5(str);
		//组织签名数据结束
		
		
		Map<String ,Object> paramMap = new HashMap<String ,Object>();
		paramMap.put("appKey", appKey);
		paramMap.put("reqSource", reqSource);
		paramMap.put("method", mothed);
		paramMap.put("sign", sign);
		paramMap.put("timestamp", timestamp);
		
		Map<String ,Object> loginMap = new HashMap<String ,Object>();
		loginMap.put("userName", "c888");
		loginMap.put("passWord", "woyaoying");
		
		String ds = Base64Util.encode(JSONObject.toJSONString(loginMap));
		System.out.println(JSONObject.toJSONString(loginMap));
		
		Map<String ,Object> ppmap = new HashMap<String ,Object>();
		ppmap.put("encrypt", ds);
		
		paramMap.put("data", ppmap);
		
		
		String body = JSONObject.toJSONString(paramMap);
		System.out.println(body);
		String ret = HttpUtil.postJson(url, body, null);
		System.out.println(ret);
		
		
	}
	
	
	public static void sing() throws Exception {
		
		//{"appKey":"4g4gs65gfgsf4gf","data":{"encrypt":"eyJ1c2VyTmFtZSI6ImxpdXlhbjE2ODkiLCJwYXNzV29yZCI6Ijg4ODg4OCJ9"},"method":"api.appgame.login","reqSource":"SHENYANG_APP_GAME","sign":"5B7384708231CC20424538F22E4D05ED","timestamp":"1554276172785"}
		
		String appKey="4g4gs65gfgsf4gf";
		String appsecret = "as323434ds454gfdd";
		long timestamp = 1554276172785L;
		
		//组织签名数据
				String str = appKey + appsecret + timestamp;
				str = Base64Util.encode(str);
				String sign = MD5.passmd5(str);
				
				
				System.out.println(sign);
		
	}
	
	public static void recharge() throws Exception {
		String url = "http://localhost:8080/game/api";//本机
		url = "http://47.101.163.99:8081/game-web/api";//测试
		url = "http://my.vrtclub.io/game/api";//生产
		//url = "http://13.57.209.180:8080/game/api";
		url = "http://47.102.39.117:8080/game/api";
		String mothed = "api.appgame.recharge";
		String appKey="4g4gs65gfgsf4gf";
		String appsecret = "as323434ds454gfdd";
		String reqSource="SHENYANG_APP_GAME";
		String timestamp="" + new Date().getTime();
		
		
	
		//组织签名数据结束
		
		Map<String ,Object> paramMap;
		
//		Map<String ,Object> paramMap = new HashMap<String ,Object>();
//		paramMap.put("appKey", appKey);
//		paramMap.put("reqSource", reqSource);
//		paramMap.put("method", mothed);
//		paramMap.put("sign", sign);
//		paramMap.put("timestamp", timestamp);
//		
		
		RechargeParam reMap = new RechargeParam();
		
		
		
		String strs = "88411,40:89925,30:90350,45:92507,220:93214,260:93772,115:103253,1000:106682,5:108837,690:111864,230:113516,290:124451,10:126019,10:126383,295:134343,300:137702,80:139290,10:149073,3:150734,320:157832,40:164050,105:168621,5:177717,600:179211,290:181753,300:181778,200:186848,240:205207,300:206492,10:244686,2:254043,50:254970,945:265912,5:270963,205:276267,140:277180,5:277888,10:278908,5:287078,600:297455,115:308778,250:318756,260:355258,245:375956,300:400402,5:400520,350:430595,1000:488774,60:521174,20:553075,2915:565698,135:574829,300:575214,6400:575312,15:575967,325:576324,575:577105,150:577499,65:577791,300:577927,50:578247,300:578295,10:578318,15:578520,300:578588,255:578794,5:578842,1070:579085,5:579536,270:579716,5:579870,420:580309,195:580581,50:581501,200:582079,300:583408,5:584731,5:585179,2:585291,10:585609,30:585613,20:586252,130:587551,5:588105,150:588496,100:589099,1760:589134,170:589607,300:590107,300:590371,1000:591765,18020:591947,5:591990,20:592108,300:592281,5:592817,1670:593351,7:594064,2625:594106,1000:594113,25105:596439,800:596873,300:597825,5:597943,270:598096,105:598335,310:598772,710:598969,10:599109,110:600165,5:600401,20:600511,17:600997,675:601084,50:602080,300:602342,380:602513,270:603168,55:603753,1:604549,5:605070,200:605470,500:605792,8:606608,300:606780,200:608112,500:609151,40:610925,1000:612049,5:612421,305:612874,240:613325,95:613327,105:614096,300:614145,285:614956,50:615845,210:617244,5:618850,55:620942,2100:622098,260:622823,6:623969,25:625395,205:625576,5:627333,295:629113,5:629652,60:630100,25:630427,340:631264,10:631353,5:631447,300:631701,20:632939,300:633175,640:633267,2:633570,17:633898,1345:634957,5:637857,3805:638296,300:639033,300:639626,225:644246,723:645948,4:647453,5:650779,250:663221,20:667736,5:670670,5:674352,835:686180,8:686437,300:689112,5:698725,245:698806,150:699440,600:708965,400:709625,248:712976,220:732277,500:751931,75:785668,395:795407,3185:796549,17405:796590,174140";
		strs = "785668,100";
		String str1[] = strs.split(":");
		
		for(int i = 0 ; i < str1.length ; i++) {
			
			timestamp="" + new Date().getTime();
			//组织签名数据
			String str = appKey + appsecret + timestamp;
			str = Base64Util.encode(str);
			String sign = MD5.passmd5(str);
			
			
			paramMap = new HashMap<String ,Object>();
			paramMap.put("appKey", appKey);
			paramMap.put("reqSource", reqSource);
			paramMap.put("method", mothed);
			paramMap.put("sign", sign);
			paramMap.put("timestamp", timestamp);
			
			
			reMap = new RechargeParam();
			String temp = str1[i];
			String str2[] = temp.split(",");
			if(StringUtils.isNotBlank(str2[0])  && StringUtils.isNotBlank(str2[1]) ) {
				//System.out.println(str2[0] + "      ====================  " + str2[1]);
				
				int amt = Integer.parseInt(str2[1]);
				amt = amt + 100;
				
				Long uid = Long.valueOf(str2[0]);
                /**********************************************************************************/				
				reMap.setBusinessType(1);
				reMap.setAmount(amt);
				reMap.setPayPass("ccccccc");
				reMap.setUserId(uid);
				//reMap.setOrderId("11111199999" + uid);
				reMap.setOrderId("85665223243211999");
				reMap.setChannel("ZHONGLE_H5");
				
				String ds = Base64Util.encode(JSONObject.toJSONString(reMap));
				//System.out.println(JSONObject.toJSONString(reMap));
				
				Map<String ,Object> ppmap = new HashMap<String ,Object>();
				ppmap.put("encrypt", ds);
				paramMap.put("data", ppmap);
				
				String body = JSONObject.toJSONString(paramMap);
				System.out.println(uid + "------>>>     " + body);
				String ret = HttpUtil.postJson(url, body, null);
				System.out.println(uid + "------>>>     " + ret);
				//	Thread.sleep(122000);
				Thread.currentThread().sleep(90000);
				//break;
			}
			
		}
		
		
		
		
		
		
	}
	
	
	
	
	
	public static void staticRequest() throws Exception {
		
		String uuid = UUID.randomUUID().toString().replaceAll("-", "");
		
		//tring id = new String()); 
		
		VrtServiceImpl vrt = new VrtServiceImpl();
		Map<String,Object> noticeMap = new HashMap<String,Object>();
		//recharge : 充值 cashwithdrawal: 提现
		noticeMap.put("orderType", "recharge");
		noticeMap.put("userId","642727");
		noticeMap.put("businessType","game");
		noticeMap.put("time",DateTimeUtil.getDate(DateTimeUtil.LONG_TIME_FORMAT));
		noticeMap.put("amount","2000000");
		noticeMap.put("orderId", uuid);
		
	
		
//		VrtResult ret = vrt.pushVrtClub(noticeMap, "/saveGameChargeLog" , LogType.NOTICE_VRT_CLUB);
//		System.out.println("----: " + JSONObject.toJSONString(ret));
//		Map<String,Object> loginMap = new HashMap<String,Object>();
//		noticeMap.put("userName", "recharge");
//		noticeMap.put("passWord","1111111");
		//VrtResult ss = vrt.pushVrtClub(noticeMap, "/login" , LogType.NOTICE_VRT_CLUB_LOGIN);
		//System.out.println("----: " + JSONObject.toJSONString(ss));
		
		String str = "";
		
		str = HttpUtil.post("http://localhost:8080/game/api/postvrt", noticeMap);
		
		System.out.println(uuid + "						--------:					 " + str);
		
	}

}
